import React from "react";
function windowWidthHoc(Component) {
  class WrapperedComponent extends React.Component {
    state = {
      windowWidth: window.innerWidth,
    };

    getWidth = () => {
      const windowWidth = window.innerWidth;
      this.setState({ windowWidth });
      console.log(windowWidth)
    };
    componentDidMount() {
      window.addEventListener("resize", this.getWidth);
    }
    componentWillUnmount() {
      window.removeEventListener("resize", this.getWidth);
    }

    render() {
      const { windowWidth } = this.state;
      return (
        <Component
          {...this.props}
          windowWidth={windowWidth}
        />
      );
    }
  }
  return WrapperedComponent;
}
export default windowWidthHoc;
